package com.api.apigateway.risk;

/**
 * 风控决策结果
 * 运行逻辑：
 * - filter(...) 打完分后，得到一个决策：放行 / 加严 / 拦截；
 * - nearBlock=true 表示高风险但先“加严”（验证码/二次验证/更小配额）；
 * - reason 带可观察标签，便于审计与回放。
 */
public class RiskDecision {
    public boolean allow;          // 是否放行（true 直接转发）
    public boolean nearBlock;      // 高风险但先加严（验证码/灰度/小配额）
    public String reason;          // 决策原因（如 RULE_IP_BURST / MODEL_IFOREST / OCSVM_HIGH）
    public double score;           // 综合风险分（0~1，越大越危险）
    public double ruleScore;       // 规则分（0~1）
    public double modelScore;      // 模型分（0~1）

    public static RiskDecision pass(String reason, double score, double ruleScore, double modelScore){
        RiskDecision d = new RiskDecision();
        d.allow = true; d.nearBlock = false; d.reason = reason; d.score = score; d.ruleScore=ruleScore; d.modelScore=modelScore;
        return d;
    }
    public static RiskDecision tighten(String reason, double score, double ruleScore, double modelScore){
        RiskDecision d = new RiskDecision();
        d.allow = true; d.nearBlock = true; d.reason = reason; d.score = score; d.ruleScore=ruleScore; d.modelScore=modelScore;
        return d;
    }
    public static RiskDecision block(String reason, double score, double ruleScore, double modelScore){
        RiskDecision d = new RiskDecision();
        d.allow = false; d.nearBlock = true; d.reason = reason; d.score = score; d.ruleScore=ruleScore; d.modelScore=modelScore;
        return d;
    }
}